﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/Attendance.master" AutoEventWireup="true" CodeFile="MyTickets.aspx.cs" Inherits="LDAP.Web.View.Attendance.MyTickets" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link rel="stylesheet" href="<%= StaticDomain %>/scripts/util/JqModal/JqPopU.css?r=<%= R %>" />
    <style type="text/css">
        .niceTab th, .niceTab td {
            line-height: 30px;
            font-size:12px;
            height:auto;
            color:black;
        }
        .kqDetail td, .formDetail td {
            background-color:white;
            padding: 3px 12px; 
            border-top:1px solid #E6E6E6;
        }
        .formDetail td {
            text-align: left;
        }
        .formDetail label {
            display:inline-block; margin-right:16px; line-height:24px;
        }
        .formDetail ol {
            padding-left: 20px;
            margin-bottom:0;
        }
        .formDetail li{
            list-style-position:outside;
        }
        .tipss span {
            color: red;
        }
        .tipss .tipsss {
            padding:0 5px;
            color: black;
        }
    </style>
    
    <script type="text/javascript" src="<%= StaticDomain %>/scripts/util/My97DatePicker/WdatePicker.js"></script>
    <style type="text/css">
        .Wdate {
            height:34px;
        }
    </style>
    <script type="text/javascript" src="<%= StaticDomain %>/scripts/util/JqModal/JqPopU.js?r=<%= R %>"></script>
    <script type="text/javascript" src="<%= StaticDomain %>/scripts/util/template/trimpath-template.js"></script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div>
      <nav class="navbar navbar-default" role="navigation">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">选择月份</a>
        </div>
        <div class="collapse navbar-collapse">
          <form class="navbar-form navbar-left" role="search">
            <div class="form-group">
              <input type="text" class="form-control Wdate" value="<%= Year %>年<%= Month.ToString().PadLeft(2,'0') %>月" id="month" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy年MM月',maxDate:'<%= DateTime.Today.Year %>-<%= DateTime.Today.Month.ToString().PadLeft(2,'0') %>-01'})" />
            </div>
            <button class="btn btn-default" type="button" id="transfer">确定</button>
          </form>
        </div>
      </nav>
    </div>

    <table class="niceTab" cellspacing="0" cellpadding="0" border="0">
        <thead>
            <tr><th>单据号</th><th>单据类型</th><th>异常类型</th><th>提交时间</th><th>影响时间</th><th>审批状态</th><th>审批人</th><th>审批时间</th><th style="width:300px;text-align:left;">批注</th></tr>
        </thead>
        <tbody id="exfBody">
            <tr><td colspan="9">加载中..</td></tr>
        </tbody>
    </table>

    <textarea name="ticketItem" id="ticketItem" style="display:none;">
        {for l in list}
        <tr>
            <td>@{l.Id}</td>
            <td><a href="javascript:void(0)" onclick="page.showExceptionForm(@{l.Id})">{if l.Type<=11&&l.Type>=9}加班单{else}异常单{/if}</a></td>
            <td>@{showTypeName(l.Type)}</td>
            <td>@{l.CreateTime.ToDate().Format("yyyy-MM-dd hh:mm:ss")}</td>
            <td>@{l.ExceptionStartDate.ToDate().Format("yyyy-MM-dd")}{if l.ExceptionEndDate.ToDate() - l.ExceptionStartDate.ToDate() == 0} {else} - @{l.ExceptionEndDate.ToDate().Format("yyyy-MM-dd")}{/if}</td>
            <td>{if l.Status == 100}审批通过{elseif l.Status == 10}<span style="color:red;">审批拒绝</span>{else}<span style="color:gray;">暂未审批</span>{/if}</td>
            <td>@{getAngelName(l.PassUserId)}</td>
            <td>{if l.PassTime != "/Date(-62135596800000+0800)/"} @{l.PassTime.ToDate().Format("yyyy-MM-dd hh:mm:ss")}{/if}</td>
            <td style="text-align:left;">{if l.Comment !=null}@{l.Comment.replace(/\n/g,"<br />")}{/if}</td>
        </tr>
        {forelse}
        <tr><td colspan="9">无相关单据</td></tr>
        {/for}
    </textarea>

    <textarea name="demoItem" id="demoItem" style="display:none">
        <table class="niceTab formDetail" cellspacing="0" cellpadding="0" border="0">
            <tr>
                <th>日期</th>
                {if ExceptionEndDate.ToDate()-ExceptionStartDate.ToDate()!=0}                   
                    <td>@{ExceptionStartDate.ToDate().Format("yyyy-MM-dd")} - @{ExceptionEndDate.ToDate().Format("yyyy-MM-dd")}</td>
                {elseif}
                    <td>@{ExceptionStartDate.ToDate().Format("yyyy-MM-dd")}</td><%--<th>时段</th><td>{if DurationType ==1}上午{elseif DurationType==2}下午{else}全天{/if}</td>--%>
                {/if}
                <th>时长</th><td>@{showTimeTypeName(Duration)}</td>
            </tr>
            <tr><th>类型</th><td colspan="3">@{showTypeName(Type)}</td></tr>
            <tr><th>异常证明</th><td colspan="3"><ol id="attachShow" style="line-height:24px;"></ol></td></tr>
            {if PassUserId!=null}
            <tr><th>审批人</th><td>@{getAngelName(PassUserId)}</td><th>审批时间</th><td>@{PassTime.ToDate().Format("yyyy-MM-dd hh:mm")}</td></tr>
            {/if}
            <tr>
                <th>审批状态</th>
                <td colspan="3">{if Status==100}审批通过{elseif Status==10}<span style="color:red;">审批拒绝</span>{else}<span style="color:gray;">暂未审批</span>{/if}</td>
            </tr>
            {if Comment!=null && Comment!=""}
            <tr><th>批注</th><td colspan="3">@{Comment.replace(/\n/g,'<br />')}</td></tr>
            {/if}
        </table>
    </textarea>

    <script type="text/javascript">
        $(document).ready(function () {        
            $("#transfer").click(page.transfer);
            page.init();
        });

        var page = {
            uploading: false,
            handler: "/handler/attendanceControl.ashx?action=",

            transfer: function () {
                var date = $("#month").val().match(/\d+/g);
                window.location.href = "/Attendance/MyTickets.aspx?y=" + date[0] + "&m=" + date[1];
                return false;
            },

            init: function () {
                $("#exfBody").html(TrimPath.processDOMTemplate("ticketItem", {list: page.exceptionForm}));
            },
            
            showExceptionForm: function(id){
                var match = null;
                $.each(page.exceptionForm, function(i,q){
                    if(q.Id==id){
                        match = q;
                        return false;
                    }
                });

                if(match==null){
                    alert("一定是哪里出什么问题了，刷新页面看看");
                    window.location.reload();
                    return false;
                }

                page.popU = page.popU || new PopU();
                page.popU.initPop({
                    type: 'string',
                    title: "异常单据",
                    contents: TrimPath.processDOMTemplate("demoItem", match),
                    w: 650,
                    onYesFn: match.Status == 0 ? function () {
                        if(confirm("您确定作废当前单据么？")){
                            $.post(page.handler +"delExceptionForm", {id: id}, function(data){
                                if(data && data.code==1){
                                    var temp = [];
                                    $.each(page.exceptionForm, function(i,q){
                                        if(q.Id!=id)
                                            temp.push(q);
                                    });
                                    page.exceptionForm = temp;
                                    $("#ef_ex_"+id).parent().remove();
                                    if(page.popU)
                                        page.popU.close();
                                }
                                else{
                                    alert("出错了，刷新看看？");
                                    window.location.reload();
                                }
                            },"json");
                        }
                    }: undefined,
                    ShowYesBtnValue: "作废",
                    onNoFn: function(){},
                    ShowNoBtnValue: "关闭"                  
                });
                page.popU.showPop();

                $.get(page.handler +"getAttachementInfo", {id: match.Attachement}, function(data){
                    if(data && data.code==1){
                        $.each(data.list, function(i,q){
                            $("#attachShow").append("<li><a target='_blank' href='" + q.Path + "'>" + q.FileName + "</a></li>");                                
                        });
                    }
                    else{
                        $("#attachShow").parent().html("加载附件异常，请刷新后重试");
                    }
                },"json");
            },

            getMousePosition: function (ev) {
                ev = ev || window.event;
                if (ev.pageX || ev.pageY)
                    return { x: ev.pageX, y: ev.pageY };
                else
                    return {
                        x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
                        y: ev.clientY + document.body.scrollTop - document.body.clientTop
                    };
            }
        };

        page.exceptionForm = <%= ToJson(ExceptionForm) %>;
        page.angelList = <%= ToJson(AngelList) %>;
    </script>
</asp:Content>